﻿using ShieldNet.Data;
using ShieldNet.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ShieldNet.Controllers
{
    public class HomeController : Controller
    {
        private readonly IDataSpam dataSpam = new DataSpam();
        
        public ActionResult Index()
        {
            var model = new SpamsInDayObject();
            model = dataSpam.Select_SpamsInfo_InDay(15, 0);
            return View(model);
        }

        [HttpPost]
        public JsonResult Get_SpamsInfo_InDay(int id, int top)
        {
            if (!ShieldNet.Extensions.ForgeryToken.ValidateRequestHeader(Request))
            {
                return Json(new { Status = 0, Message = "ValidateRequestHeader False" });
            }
            int status = 1;
            var data = new SpamsInDayObject();
            data = dataSpam.Select_SpamsInfo_InDay(top, id);
            if (data.TotalDay == 0 || data.SpamsObject.Count == 0)
            {
                status = 0;
            }
            return Json(new { Status = status, Data = data});
        }
        [HttpGet]
        public JsonResult Get_TableSpam(int offset = 1, int limit = 15)
        {
            if (!ShieldNet.Extensions.ForgeryToken.ValidateRequestHeader(Request))
            {
                return Json(new { Status = 0, Message = "ValidateRequestHeader False" });
            }
            var obj = new TableSpams();
            if (offset <= 0) offset = 1;
            obj = dataSpam.Get_TableSpams(offset, limit);
            return Json(obj, JsonRequestBehavior.AllowGet);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}